<?php 
$this->pageTitle=Yii::app()->name . ' - '.UserModule::t("Profile");
$this->breadcrumbs=array(
		'Tài khoản cá nhân',
);

$this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'r1'));
?>
<div class="iportlet">
	<div class="iportlet-title"><h3>Cá nhân</h3></div>
	<div class="portlet-content">
		<div><a href="<?php echo Yii::app()->createUrl('/user/profile/edit', array('id'=>Yii::app()->user->id));?>">Thông tin cá nhân</a></div>
		<div><a href="<?php echo Yii::app()->createUrl('/user/order');?>">Đơn hàng của tôi</a></div>
	</div>
</div>
<?php 
$this->endWidget();

?>
<div class="head-tool">
	<div class="main-title"><?php echo UserModule::t("Profile page"); ?></div>
</div>
<div class="content-box">
<?php if(Yii::app()->user->hasFlash('profileMessage')): ?>
<div class="success">
<?php echo Yii::app()->user->getFlash('profileMessage'); ?>
</div>
<?php endif; ?>
<div class="form" style="overflow: hidden">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'profile-form',
	'enableAjaxValidation'=>false,
	'htmlOptions' => array('enctype'=>'multipart/form-data'),
)); ?>

	<?php echo $form->errorSummary(array($model,$profile)); ?>
<div style="float: left">
<?php 
		$profileFields=$profile->getFields();
		if ($profileFields) {
			foreach($profileFields as $field) {
			?>
	<div class="row">
		<?php echo $form->labelEx($profile,$field->varname);
		
		if ($widgetEdit = $field->widgetEdit($profile)) {
			echo $widgetEdit;
		} elseif ($field->range) {
			echo $form->dropDownList($profile,$field->varname,Profile::range($field->range));
		} elseif ($field->field_type=="TEXT") {
			echo $form->textArea($profile,$field->varname,array('rows'=>6, 'cols'=>50));
		} else {
			echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255)));
		}
		echo $form->error($profile,$field->varname); ?>
	</div>	
		<?php
			}
		}
		?>
	<div class="row">
		<?php echo $form->labelEx($model,'fullname'); ?>
		<?php echo $form->textField($model,'fullname'); ?>
		<?php echo $form->error($model,'fullname'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'email'); ?>
		<?php echo $form->textField($model,'email',array('size'=>60,'maxlength'=>128)); ?>
		<?php echo $form->error($model,'email'); ?>
	</div>
	<div class="el-dialogform row">
				<fieldset>
					<legend><label>Avatar</label></legend>
					
					<div id="uploaded_avatar">
						<?php if($model->avatar!=''):?>
						<img id="avatar" src="<?php echo Yii::app()->params['storage_url'].'/profile/'.$model->id.'/thumb/'.$model->avatar;?>" />
						<?php else:?>
						<img width="110" src="<?php echo Yii::app()->theme->baseUrl;?>/images/avatar.jpg" />
						<?php endif;?>
					</div>
					<br class="clear" />
					<div class="wb-upload">
					<?php $this->widget('MUploadify',array(
						'name'=>'User[avatar]',
						'buttonText'=>Yii::t('app','Upload Image'),
						'script'=>array('/user/profile/upload'),
						'model_id'=>$model->id,
						'fileExt'=>'*.jpg;*.png;',
						'auto'=>true,
					  //fileDesc=>Yii::t('application','Image files'),
					  //'uploadButton'=>true,
					  //'uploadButtonText'=>'Upload new',
					  //'uploadButtonTagname'=>'button',
					  //'uploadButtonOptions'=>array('class'=>'myButton'),
						'onComplete'=>'js:function(event, id, obj,respone, data){
							if(respone=="error_file_type"){
								alert("Upload lỗi.Kiểu file không hợp lệ.")
							}else if(respone=="error_file_upload"){
								alert("Lỗi upload.Không thể upload file.Hãy kiểm tra lại quyền thư mục upload file.")
							}else{
							 	$("#uploaded_avatar").html("<img src=\""+respone+"\" />");
							 	$("#wb-del-avatar").html("<a class=\"wb-del\" href=\"javascript:void(0);\" onclick=\"DelImage('.$model->id.');\" >'.Yii::t('app','Delete').'</a>");
							}
						}',
					));
					?>
					</div>
					<div class="toolb-i">
						<div id="wb-del-avatar">
							<?php if(!empty($model->avatar)):?>
							<a class="wb-del" href="javascript:void(0);" onclick="DelImage(<?php echo $model->id;?>);">
							<?php echo Yii::t('app','Delete');?>
							</a>
							<?php endif;?>
						</div>
					</div>
					
				</fieldset>
				</div>
	</div>
	
	<button type="submit" class="button">Lưu</button>
<?php $this->endWidget(); ?>

</div><!-- form -->
</div>